<%--
 *  File:   uploadcolumncheck.jsp
 *  Desc:	
 *
 *  Date	  :	 2013-05-31     
 *  Author	:  jeanhuang
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
	//init param
  String strModuleName = "IMG";
  String privilegeCode = "IMG0303";
  String contextPath = request.getContextPath();
  
  String struploadconfigid=request.getParameter("uploadconfigid")+"";
  if(session.getAttribute("uploadconfigid")!=null){
		struploadconfigid=session.getAttribute("uploadconfigid")+"";
	}
%>
<%@ include file="/inc/CommonHeader.inc" %>

<html>
<head>
<title>uploadcolumncheck</title>
<PageFlow:CheckPageFlow pageName="p_uploadcoloumncheck"/>
<%@ include file="/inc/AlertError.inc" %>
<%@ include file="/inc/SummaryDivision.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<%
  Vector configcolumnchecks = (Vector)pageContext.getAttribute("configcolumnchecks");
Vector checkcolumninfo = (Vector)pageContext.getAttribute("checkcolumninfo");

  if(configcolumnchecks == null) configcolumnchecks = new Vector();
  String paramstr="";
  if(struploadconfigid!=null&&struploadconfigid!=""){
	  paramstr="&uploadconfigid=" + struploadconfigid+"&flag=edit";
  }else{
	  paramstr="&flag=new";
  }

%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript">
<%if(checkcolumninfo==null||(checkcolumninfo!=null&&checkcolumninfo.size()==0)){%>
alert("<%= message.getMessageDesc("SAVE_COLUMN_INO_FIRST") %>");
var link='uploadconfigfrm.jsp?<%= OvalTools.randomURL() %><%=paramstr%>';
	parent.parent.location.href=link;
	
<%}%>
function clickComboCode(id)
{
  document.cform.id.value = id;
}

function page_add()
{
    //if(!checkALLElems(document.getElementById("newdetail"))) return;
    if(!checkForm(cform)) return;
    if (cform.checkruleid.value==2 || cform.checkruleid.value==3) {
    	document.cform.condition2.value=document.cform.columnname.value;
    	document.cform.valuecolumn.value=document.cform.valuecolumns.value;
    }
    //changedField();
    cform.actionname.value = "add";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_delete()
{
    if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>")) return;
    cform.actionname.value = "delete";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function page_save()
{
    if(!checkALLElems(document.getElementById("olddetail"))) return;
    emptyToNull(cform);
    cform.actionname.value = "save";
    cform.target = "_self";
    isRunning = true;
    cform.submit();
}
function changedField()
{
cform.columntypenew.options[cform.tablefield.selectedIndex].selected=true;
cform.columntype.value=cform.columntypenew.value;
}
function page_back(){
	parent.location.href="uploadConfigSummary.jsp?<%=OvalTools.randomURL()%>";
}

function setReadonly(){
	var numrows = cform.numrows.value;
	for(var i=0 ; i < numrows; i++){
		eval("cform.sourcesequence"+i).disabled = "disabled";
	}
}

function checklength(){
	var length  = cform.sourcesequence.value.length;
	if(length > 4){
		var value = cform.sourcesequence.value;
		cform.sourcesequence.value = value.substring(0, 4);
	}
}

function changevalue(obj){
	if(obj.checked){
		document.cform.iskeycolumn.value='Y';
	}else{
		document.cform.iskeycolumn.value='N';
	}
}

function changesetvalue(obj){
	var textobj=obj.options[obj.selectedIndex].text;
	if(obj.value!=""&&obj.value!=null&&obj.value!=-1){
		document.cform.uploadcolumnconfigid.value=textobj;
		setkeyvalue(obj.value,textobj);
	}else{
		document.cform.tablename.value="";
	}
}

function conditionChange(){
	var value = cform.checkruleid.value;
	if (value == 3) {
		_back();
		cform.tablename.style.display="block";
		document.cform.columnname.style.display="block";
	   	document.cform.valuecolumns.style.display="block";
	   	document.cform.othercondition.style.display="block";
	   	
	   	document.cform.tablename.command="notnull";
	   	document.cform.tablename.label="<%= label.getLabelName("L_TableName") %>";
	   	
	   	document.cform.columnname.command="notnull";
	   	document.cform.columnname.label="<%= label.getLabelName("L_ContactColumn") %>";
	}else if (value == 5) {
		_back();
		document.cform.condition1.style.display="block";
		
		document.cform.condition1.command="notnull";
	   	document.cform.condition1.label="<%= label.getLabelName("L_SQL") %>";
	}else if (value == 2) {
		_back();
		//cform.tablename.style.display="block";
		cform.condition1.style.display="block";
		document.cform.columnname.style.display="block";
	   	document.cform.valuecolumns.style.display="block";
	   	
	   	document.cform.condition1.command="notnull";
	   	document.cform.condition1.label="<%= label.getLabelName("L_DicType") %>";
	   	
	   	document.cform.columnname.command="notnull";
	   	document.cform.columnname.label="<%= label.getLabelName("L_ContactColumn") %>";
	}else if (value == 4) {
		_back();
	   	document.cform.uploadcolumnconfigidOne.style.display="block";
			   	
	   	document.cform.uploadcolumnconfigidTwo.style.display="block";

	   	cform.uniquetablename.style.display="block";
	   	
	}else {
		_back();
	}
}

function _back() {
	document.cform.condition1.value="";	
	cform.tablename.style.display="none";
	cform.uniquetablename.style.display="none";
	cform.uploadcolumnconfigidOne.style.display="none";
	cform.uploadcolumnconfigidTwo.style.display="none";
	document.cform.columnname.style.display="none";
	document.cform.valuecolumns.style.display="none";
	document.cform.condition1.style.display="none";
	document.cform.othercondition.style.display="none";
	document.cform.valuecolumns.length=1;
	document.cform.columnname.length=1;
	forvaluecolumns = true;
	forcolumns = true;
	
	document.cform.condition1.command="";
	document.cform.condition1.label="";
	document.cform.columnname.command="";
	document.cform.columnname.label="";
}

var forvaluecolumns = true;
var forcolumns=true;

function cleancolumns(obj) {
	forvaluecolumns = true;
	forcolumns = true;
	document.cform.valuecolumns.length=1;
	document.cform.columnname.length=1;
	
	document.cform.condition1.value=obj.value;
}

function cleancolumnsnew(obj) {
	forvaluecolumns = true;
	forcolumns = true;
	
	document.cform.othercondition.value=obj.value;
}

function getvaluecolumns(){
	  if (!forvaluecolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.valuecolumns.length=1;
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.valuecolumns");
	  datahandler.runDataHandler();
	  
	  forvaluecolumns = false;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "uploadcolumncheck.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function getcolumns(){
	if (!forcolumns) {
	  	return;
	  }
	  var value=cform.condition1.value;
	  if (cform.checkruleid.value ==2) value='DICTIONARY';
	  document.cform.columnname.length=1;
	  var  datahandler = new  DataHandler() ;
	  datahandler.add_params("tablename" ,value,"String");
	  //datahandler.add_params("ispk" ,'N',"String");
	  datahandler.add_params("languagecode" ,"<%=strLanguageCode %>","String");
	  datahandler.add_job("j_gettableinfo");
	   
	  datahandler.getResultFromVector("columndatas","columnname" ,"columnname","document.cform.columnname");
	  datahandler.runDataHandler();
	  
	  forcolumns = false;
}

function setconditionvalue(obj,type){
	eval("document.cform.condition"+type).value=obj.value;
}

function page_update()
{
  var id = document.cform.id.value;
	if(id == null || id.length == 0 || id == "" || id == "-1")
	   return;
  var link = "ChangeColumnCheck.jsp?uploadconfigid=<%=struploadconfigid%>&uploadcolumncheckid="+id;
  
  parent.down.location.href = link;
}

</script>
<body style="overflow: auto;">
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher" >
  <input type="hidden" name="pagename" value="p_uploadcoloumncheck">
  <input type="hidden" name="actionname">
  <custom:hidden property="uploadconfigid" value="<%=struploadconfigid %>" />
  <input type="hidden" name="numrows" value="<%= configcolumnchecks.size() %>">

<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                    <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">
<tr  class="deepblue-left"> 
	<td width="5%" class="title_center">&nbsp;</td>
	<td width="15%" class="title_center"><%= label.getLabelName("L_SortNo") %><font color="red">*</font></td>
	<td width="10%" class="title_center"><%= label.getLabelName("L_RowName") %><font color="red">*</font></td>
	<td width="20%" class="title_center"><%= label.getLabelName("L_CheckRule") %><font color="red">*</font></td>
	<td width="15%" class="title_center"><%= label.getLabelName("L_Condition") %>1</td>
	<td width="15%" class="title_center"><%= label.getLabelName("L_Condition") %>2</td>
	<td class="title_center"><%= label.getLabelName("L_Value") %><%= label.getLabelName("L_Field") %></td>
	<td class="title_center"><%= label.getLabelName("L_Other") %><%= label.getLabelName("L_Condition") %></td>
		
</tr>
<span id="olddetail" >
				 		  <%
				             int j = 0;
				             String strClassType = new String();
				             Integer nDefaultId = new Integer(-1);
				             boolean bHasChecked = false;
				          %>
                    <logic:iterate id="onerow" collection="<%= configcolumnchecks %>" indexId="idx">
                        <%
				            HashMap hashdatas = (HashMap)pageContext.getAttribute("onerow");
				
				            String strIsDisabled = new String("");
				            String strIsChecked = new String("");
				
				            if(j%2 == 1){
				              strClassType = "td-listrom";
				            }else{
				              strClassType = "";
				            }
				           if(!bHasChecked)
				            {
				              strIsChecked = "Checked";
				              bHasChecked = true;
				              nDefaultId = (Integer)(hashdatas.get("uploadcolumncheckid"));
				            }
				            j++;
         			 %>
                      <tr>
                        <td width="30">
                        <input id="deletes<%=JspHelper.filterNull(j)%>" type="radio" name="checkdept"  value=<%=JspHelper.filterNull( hashdatas.get("uploadcolumncheckid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked)%> onClick="javascript:clickComboCode('<%=JspHelper.filterNull( hashdatas.get("uploadcolumncheckid") )%>')">
                        </td>
                        <td><custom:write property="columnno" name="onerow"  nbsp="true"/></td>
                        <td>
                        <custom:write property="columnname" name="onerow" nbsp="true" />
                        </td>
                        <td><custom:write property="checkruleid" name="onerow" nbsp="true" dictType="columncheckrule"/></td>
                        <td><custom:write property="condition1" name="onerow" nbsp="true" /></td>
                     	<td><custom:write property="condition2" name="onerow" nbsp="true" /></td>
                       	<td><custom:write property="valuecolumn" name="onerow" nbsp="true" /></td>
                       	<td><custom:write property="othercondition" name="onerow" nbsp="true" /></td>
                  
                   </tr>
                      
                      </logic:iterate>
                      <% if(!isView){%>

<span id="newdetail" >
                      <tr >
                        <td>&nbsp;</td>
                        
                        <td><input type="text" name="columnno" /></td>
                        
                       <td>
                       	 <custom:select optionsName="checkcolumninfo" name="newdetail" property="uploadcolumnconfigid" optionInnerTextKey="columndesc" optionValueKey="uploadcolumnconfigid" defaultValue="---------"  command="notnull" label="L_RowName"/>
<!--                       	 <custom:hidden name="newdetail" property="uploadcolumnconfigid" />-->
                        </td>

                  		<td>
             		    	<custom:selectdic name="newdetail" property="checkruleid" dictType="columncheckrule" defaultValueCost="" defaultValue="---------" onchange="conditionChange();" command="notnull" label="L_CheckRule"/>
                        </td>

                        <td>
                       	 <custom:select optionsName="alltables" name="newdetail" property="tablename" optionInnerTextKey="tablevalue" optionValueKey="tablename" defaultValue="---------"  style="display:none" onchange="cleancolumns(this)"/>
                       	 <input type="text" name="condition1" style="display: none" size="35"/>
                       	 <custom:select optionsName="allcolumns" name="newdetail" property="uploadcolumnconfigidOne" optionInnerTextKey="columnname" optionValueKey="columnname" defaultValue="---------"  style="display:none" onchange="setconditionvalue(this,1)" />
                        </td>
                        <td>
                        	<custom:select name="newdetail" property="columnname" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" style="display:none" onclick="getcolumns()"/>
                        	<input type="text" name="condition2" style="display: none"/>
                        	<custom:select optionsName="allcolumns" name="newdetail" property="uploadcolumnconfigidTwo" optionInnerTextKey="columnname" optionValueKey="columnname" defaultValue="---------"  style="display:none" onchange="setconditionvalue(this,2)" />
                        </td>
                      	<td>
                      		<custom:select name="newdetail" property="valuecolumns" optionsName="columndatas" optionValueKey="columnname" optionInnerTextKey="columnname" defaultValue="---------" style="display:none"  onclick="getvaluecolumns()"/>
                      		<input type="text" name="valuecolumn" style="display: none"/>
                      	</td>
                      	<td>
                      		<input type="text" name="othercondition"  style="display: none" />
                      		<custom:select optionsName="alltables" name="newdetail" property="uniquetablename" optionInnerTextKey="tablevalue" optionValueKey="tablename" defaultValue="---------"  style="display:none" onchange="cleancolumnsnew(this)"/>
                      	</td>
                      </tr>

</span>
<script>
//changedField();
</script>
<%}%>
                       <%@ include file="/inc/SummaryAction.inc" %>
</span>

 <input type="hidden" name="id" value="<%=JspHelper.filterNull( nDefaultId )%>">


                    </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
         <tr><td class="summary_top"></td></tr>
         <tr>
           <td class="td_center">
          
          	  <a onclick="page_add();"><custom:button type="1" label="L_Add" imgsrc="new.gif" border="0" style="width:60"/></a>
          	  <a onclick="page_update();"><custom:button type="1" label="L_Edit" imgsrc="new.gif" border="0" style="width:60"/></a>
              <a onclick="page_delete();"><custom:button type="1" label="L_Delete" imgsrc="new.gif" border="0" style="width:60"/></a>
          
           </td>
         </tr>
      </table>
    </td>
  </tr>
</table>
</form>
</body>
<script>
	//setReadonly();
</script>
</html>